package com.acme.biz.api;

import com.acme.biz.api.enums.ResultEnum;
import lombok.Data;

@Data
public class ApiResponse <T>{

    private T data;

    private String code;

    private String msg;

    public static <T> ApiResponse<T> success(T data){
        ApiResponse response = new ApiResponse();
        response.setCode(ResultEnum.SUCCESS.getCode());
        response.setMsg(ResultEnum.SUCCESS.getMsg());
        response.setData(data);
        return response;
    }
    public static <T> ApiResponse<T> fail(ResultEnum resultEnum){
        ApiResponse response = new ApiResponse();
        response.setCode(resultEnum.getCode());
        response.setMsg(resultEnum.getMsg());
        return response;
    }
    public static <T> ApiResponse<T> fail(String code,String msg){
        ApiResponse response = new ApiResponse();
        response.setCode(code);
        response.setMsg(msg);
        return response;
    }
}
